﻿using System;
using System.Runtime.Serialization;
using System.Text;

namespace RockBus.Monitoring.DataContracts.Configuration
{
    /// <summary>
    /// Base class for the performance counter configuration.
    /// </summary>
    [DataContract(Namespace = NamespaceConstants.MonitoringNamespace)]
    [KnownType(typeof(PerformanceCounterCategoryConfiguration))]
    [KnownType(typeof(PerformanceCounterConfiguration))]
    [KnownType(typeof(PerformanceCounterInstanceConfiguration))]
    public abstract class PerformanceCounterConfigurationBase
    {
        /// <summary>
        /// The performance counter category name.
        /// </summary>
        [DataMember(IsRequired = true)]
        public string CategoryName { get; set; }

        /// <summary>
        /// The performance counter name.
        /// </summary>
        [DataMember(IsRequired = false)]
        public string CounterName { get; set; }

        /// <summary>
        /// The aggregation to be applied to the performance counter value(s).
        /// </summary>
        [DataMember(IsRequired = false)]
        public AggregationTypeEnum? AggregationType { get; set; }

        /// <summary>
        /// The full name of the performance counter. In the same format as perfmon or logman are using (i.e. 'Memory\pages/sec' or 'Processor(_Total)\% Processor Time').
        /// </summary>
        public abstract string FullName { get; }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(string.Format("CategoryName: {0}", this.CategoryName ?? string.Empty));
            sb.AppendLine(string.Format("CounterName: {0}", this.CounterName ?? string.Empty));
            sb.AppendLine(string.Format("AggregationType: {0}", this.AggregationType.ToString()));
            return sb.ToString();
        }
    }
}